﻿/*******************************************************************************
 * Anynote 共同JS定义
 *******************************************************************************/

var Menu = {};

/*******************************************************************************
 * 常量数据
 *******************************************************************************/

/*******************************************************************************
 * 方法
 *******************************************************************************/
/*******************************************************************************
 * 主页菜单
 *******************************************************************************/
Menu.getHomeAccordion = function(param){
	// 主页
	var homeAccordion = {
		contentEl: 'homeAccordionDiv',
        title: '主页',
        border: false,
        iconCls: 'house',
    	tools: [{
			id: 'refresh',
			handler: function(){
	    		var homeTree = Ext.getCmp('homeTreePanel');
				Anynote.reloadTreeNode(homeTree, null, function(){
					homeTree.expandAll();
				});
    		}
	    }]
    };
	
	// 主页树
	var homeTree = new Ext.tree.TreePanel({
		id: 'homeTreePanel',
		renderTo: 'homeAccordionDiv',
	    useArrows: true,
	    autoScroll: true,
	    animate: true,
	    enableDD: false,
	    containerScroll: true,
	    border: false,
	    dataUrl:'',
	    rootVisible: false,
	    loader: new Ext.tree.TreeLoader({
    	            baseParams: {roleid:param.role},
                    dataUrl:'${pageContext.request.contextPath}/getMenuTree.action',
                    listeners : {
					beforeload : function(treeLoader, node) {
						this.baseParams.parentId = node.id;
						this.baseParams.text = node.text;
						this.baseParams.leaf = node.leaf;
					}
				}           
        }),
	    root: new Ext.tree.AsyncTreeNode({
	        id: '18',
	        text: '主页',
	        draggable:true,                  //是否支持拖动
            nodeType: 'async', 
            leaf:false
	        //children: Menu.homeMenuData
    	}),
    	listeners: {click: function(node) {homeTreeClick(node);}}
	});
	homeTree.getRootNode().expand(true);
	
	// 树右键菜单
	var homeTreeContextMenu = new Ext.menu.Menu({
		items:[{
			text: '删除',
			iconCls: 'cross',
			handler: function(node, e){
				var selectNode = homeTree.getSelectionModel().getSelectedNode();
				if(selectNode.id=='homePage') return;
				var params = {};
				params.userMetaId = selectNode.id;
				// 发送请求
				Anynote.ajaxRequest({
					baseUrl: param.baseUrl,
					baseParams: params,
					action: '/userMetaAction.do?method=delete',
					callback: function(jsonResult){
						Anynote.reloadTreeNode(homeTree, null, function(node){
							node.expand(true);
						});
					},
					showWaiting: true,
					failureMsg: '删除失败.'
				});
			}
		}]
	});

	// 绑定树右键菜单
	homeTree.on('contextmenu',function(node,e){
		if(node.id=='homePage'){
			homeTreeContextMenu.items.get(0).disable();
		}else{
			homeTreeContextMenu.items.get(0).enable();
		}
		e.preventDefault();
		node.select();
		homeTreeContextMenu.showAt(e.getXY());
	});
	
	// 主页树的单击事件
	function homeTreeClick(node){
		if(!node.isLeaf()) return;
		var nodeId = node.attributes.id;
		var tabId = node.id;
	    if(nodeId=='19'){
			tabTitle = '告警记录';
			tabUrl = param.baseUrl + "/page/bussmodule/alarmQuery/alarmQuery.jsp";
		}
		// 	打开Tab页
		Anynote.openTab(tabTitle, tabUrl);
	}
	return homeAccordion;
}

/*******************************************************************************
 * 系统信息菜单
 *******************************************************************************/
Menu.getCountAccordion = function(param){
   var countAccordion = {
       	contentEl: 'countAccordionDiv',
		title: '系统信息',
		border: false,
		autoScroll: true,
		iconCls: 'chart_bar',
    	tools: [{
			id: 'refresh',
			handler: function(){}
	    }]
    };
    // 用户树
	var countTree = new Ext.tree.TreePanel({
		id: 'countTreePanel',
		renderTo: 'countAccordionDiv',
	    useArrows: true,
	    autoScroll: true,
	    animate: true,
	    enableDD: false,
	    containerScroll: true,
	    border: false,
	    dataUrl:'',
	    rootVisible: false,
	    root: new Ext.tree.AsyncTreeNode({
	    	id:'9',                      //节点id
	    	text: '账目树',
            draggable:true,                  //是否支持拖动
            nodeType: 'async', 
            leaf:false
	    	//children: Menu.countMenuData
    	}),
    	loader: new Ext.tree.TreeLoader({
    	            baseParams: {roleid:param.role},
                    dataUrl:'${pageContext.request.contextPath}/getMenuTree.action',
                    listeners : {
					beforeload : function(treeLoader, node) {
						this.baseParams.parentId = node.id
						this.baseParams.text = node.text
						this.baseParams.leaf = node.leaf
					}
				}           
        })
	});
	countTree.getRootNode().expand();
	
	countTree.on("click",function(node,event)
        {
            countTreeClick(node);
        });

	// 用户树的单击事件
	function countTreeClick(node){
		if(!node.isLeaf()) return;
		var nodeId = node.attributes.id;
		var tabTitle = "";
		var tabUrl = "";
		if(nodeId=='9'){
			tabTitle = "告警语音通知查询";
			tabUrl = param.baseUrl + "/page/bussmodule/sendRecord/sendRecord.jsp";
		}else if(nodeId=='11'){
			tabTitle = "告警通话流水查询";
			tabUrl = param.baseUrl + "/page/bussmodule/callStream/callStream.jsp";
		}else if(nodeId=='25'){
		    tabTitle = "工单语音通知查询";
			tabUrl = param.baseUrl + "/page/bussmodule/superviseSend/superviseRecord.jsp";
		}else if(nodeId=='26'){
		    tabTitle = "工单通话流水查询";
			tabUrl = param.baseUrl + "/page/bussmodule/superviseStream/superviseStream.jsp";
		}else if(nodeId=='27'){
		    tabTitle = "工单语音通知统计";
			tabUrl = param.baseUrl + "/page/bussmodule/superviseInfo/superviseInfo.jsp";
		}else if(nodeId=='28'){
		    tabTitle = "督办对象排名统计";
			tabUrl = param.baseUrl + "/page/bussmodule/superviseRanking/superviseRanking.jsp";
		}
		// 	打开Tab页
		Anynote.openTab(tabTitle, tabUrl);
	}
	return countAccordion;
}

/*******************************************************************************
 * 缴费业务菜单
 *******************************************************************************/
Menu.getNoticeAccordion = function(param){
   var noticeAccordion = {
       	contentEl: 'noticeAccordionDiv',
		title: '缴费业务',
		border: false,
		autoScroll: true,
		iconCls: 'phone_sound',
    	tools: [{
			id: 'refresh',
			handler: function(){}
	    }]
    };
// 用户树
	var noticeTree = new Ext.tree.TreePanel({
		id: 'noticeTreePanel',
		renderTo: 'noticeAccordionDiv',
	    useArrows: true,
	    autoScroll: true,
	    animate: true,
	    enableDD: false,
	    containerScroll: true,
	    border: false,
	    dataUrl:'',
	    rootVisible: false,
	    root: new Ext.tree.AsyncTreeNode({
	    	id:'2',                      //节点id
	    	text: '账目树',
            draggable:true,                  //是否支持拖动
            nodeType: 'async', 
            leaf:false
    	}),
    	loader: new Ext.tree.TreeLoader({
    	            baseParams: {roleid:param.role},
                    dataUrl:'${pageContext.request.contextPath}/getMenuTree.action',
                    listeners : {
					beforeload : function(treeLoader, node) {
						this.baseParams.parentId = node.id
						this.baseParams.text = node.text
						this.baseParams.leaf = node.leaf
					}
				}           
        })
	});
	noticeTree.getRootNode().expand();
	
	noticeTree.on("click",function(node,event)
        {
            noticeTreeClick(node);
        });

	// 用户树的单击事件
	function noticeTreeClick(node){
		if(!node.isLeaf()) return;
		var nodeId = node.attributes.id;
		var tabTitle = "";
		var tabUrl = "";
		if(nodeId=='10'){
			tabTitle = "话费缴费";
			tabUrl = param.baseUrl + "/page/bussmodule/phonePay/phonepay.jsp";
		}else if(nodeId=='13'){
			tabTitle = "传报人员配置";
			tabUrl = param.baseUrl + "/page/bussmodule/conscientious/cons.jsp";
		}else if(nodeId=='14'){
		    tabTitle = "传报记录核查";
			tabUrl = param.baseUrl + "/page/bussmodule/heraldRecord/heraldRecord.jsp";
		}else if(nodeId=='15'){
		    tabTitle = "告警记录";
			tabUrl = param.baseUrl + "/page/bussmodule/alarmQuery/alarmQuery.jsp";
		}else if(nodeId=='16'){
		    tabTitle = "自编信息播报";
			tabUrl = param.baseUrl + "/page/bussmodule/customSend/customSend.jsp";
		}else if(nodeId=='17'){
		    tabTitle = "通讯录";
			tabUrl = param.baseUrl + "/page/bussmodule/phonegroup/addresslist.jsp";
		}else if(nodeId=='20'){
		    tabTitle = "告警过滤配置";
			tabUrl = param.baseUrl + "/page/bussmodule/alarmpro/alarmproConfig.jsp";
		}
		// 	打开Tab页
		Anynote.openTab(tabTitle, tabUrl);
	}
	return noticeAccordion;
}

/*******************************************************************************
 * 我的账户菜单
 *******************************************************************************/
Menu.getSuperviseWorkOrder = function(param){
   var superviseworkorder = {
       	contentEl: 'superviseworkorderDiv',
		title: '我的账户',
		border: false,
		autoScroll: true,
		iconCls: 'phone_sound',
    	tools: [{
			id: 'refresh',
			handler: function(){}
	    }]
    };
// 用户树
	var superviseTree = new Ext.tree.TreePanel({
		id: 'superviseTreePanel',
		renderTo: 'superviseworkorderDiv',
	    useArrows: true,
	    autoScroll: true,
	    animate: true,
	    enableDD: false,
	    containerScroll: true,
	    border: false,
	    dataUrl:'',
	    rootVisible: false,
	    root: new Ext.tree.AsyncTreeNode({
	    	id:'3',                      //节点id
	    	text: '账目树',
            draggable:true,                  //是否支持拖动
            nodeType: 'async', 
            leaf:false
    	}),
    	loader: new Ext.tree.TreeLoader({
    	            baseParams: {roleid:param.role},
                    dataUrl:'${pageContext.request.contextPath}/getMenuTree.action',
                    listeners : {
					beforeload : function(treeLoader, node) {
						this.baseParams.parentId = node.id
						this.baseParams.text = node.text
						this.baseParams.leaf = node.leaf
					}
				}           
        })
	});
	superviseTree.getRootNode().expand();
	superviseTree.on("click",function(node,event)
        {
            superviseTreeClick(node);
        });

	// 用户树的单击事件
	function superviseTreeClick(node){
		if(!node.isLeaf()) return;
		var nodeId = node.attributes.id;
		var tabTitle = "";
		var tabUrl = "";
		if(nodeId=='15'){
			tabTitle = "存款提交";
			tabUrl = param.baseUrl + "/page/bussmodule/saving/savingSubmit.jsp";
		}else if(nodeId=='16'){
			tabTitle = "存款历史记录";
			tabUrl = param.baseUrl + "/page/bussmodule/saving/testGrid.jsp";
		}else if(nodeId=='33'){
		    tabTitle = "传报记录核查";
			tabUrl = param.baseUrl + "/page/bussmodule/supervise/heraldRecord.jsp";
		}else if(nodeId=='24'){
		    tabTitle = "督办工单记录";
			tabUrl = param.baseUrl + "/page/bussmodule/superviseQuery/superviseQuery.jsp";
		}else if(nodeId=='33'){
		    tabTitle = "自编信息播报";
			tabUrl = param.baseUrl + "/page/bussmodule/supervise/customSend.jsp";
		}else if(nodeId=='33'){
		    tabTitle = "通讯录";
			tabUrl = param.baseUrl + "/page/bussmodule/supervise/addresslist.jsp";
		}else if(nodeId=='33'){
		    tabTitle = "告警过滤配置";
			tabUrl = param.baseUrl + "/page/bussmodule/supervise/alarmproConfig.jsp";
		}
		// 	打开Tab页
		Anynote.openTab(tabTitle, tabUrl);
	}
	return superviseworkorder;
}

/*******************************************************************************
 * 个人管理
 *******************************************************************************/
Menu.getSystemAccordion = function(param){
	var systemAccordion = {
       	contentEl: 'systemAccordionDiv',
		title: '个人管理',
		border: false,
		autoScroll: true,
		iconCls: 'folder_user',
    	tools: [{
			id: 'refresh',
			handler: function(){
			   Anynote.reloadTreeNode(Ext.getCmp('systemTreePanel'), null, null);
			}
	    }]
    };
	
	// 用户树
	var systemTree = new Ext.tree.TreePanel({
		id: 'systemTreePanel',
		renderTo: 'systemAccordionDiv',
	    useArrows: true,
	    autoScroll: true,
	    animate: true,
	    enableDD: false,
	    containerScroll: true,
	    border: false,
	    rootVisible: false,
	    root: new Ext.tree.AsyncTreeNode({
	        id:'4',                      //节点id
	    	text: '账目树',
            draggable:true,                  //是否支持拖动
            nodeType: 'async', 
            leaf:false
    	}),
    	loader: new Ext.tree.TreeLoader({
    	            baseParams: {roleid:param.role},
                    dataUrl:'${pageContext.request.contextPath}/getMenuTree.action',
                    listeners : {
					beforeload : function(treeLoader, node) {
						this.baseParams.parentId = node.id
						this.baseParams.text = node.text
						this.baseParams.leaf = node.leaf
					}
				}           
        })
	});
	systemTree.getRootNode().expand();
	
	systemTree.on("click",function(node,event)
        {
            systemTreeClick(node);
        });
	
	// 树右键菜单
	var systemTreeContextMenu = new Ext.menu.Menu({
		items:[{
			text: '加入快捷菜单',
			iconCls: 'star',
			handler: function(node, e){
				var selectNode = systemTree.getSelectionModel().getSelectedNode();
				var text = selectNode.text;
				var url = '';
				if(selectNode.id=='userList'){
					text = '用户查询';
					url = '/FromThe80s/page/user/userList.jsp';
				}else if(selectNode.id=='setting'){
					text = '系统设置';
					url = '/websrc/page/system/setting.jsp';
				}
				Menu.addFavoriteMenu(param.baseUrl, text, url);
			}
		}]
	});

	// 绑定树右键菜单
	systemTree.on('contextmenu',function(node,e){
		e.preventDefault();
		node.select();
		systemTreeContextMenu.showAt(e.getXY());
	});

	// 用户树的单击事件
	function systemTreeClick(node){
		if(!node.leaf) return;
		var nodeId = node.id;
		var tabTitle = "";
		var tabUrl = "";
		if(nodeId=='4'){
			tabTitle = "用户查询";
			tabUrl = param.baseUrl + "/page/user/userList.jsp";
		}else if(nodeId=='6'){
			tabTitle = "角色查询";
			tabUrl = param.baseUrl + "/page/user/roleList.jsp";
		}else if(nodeId=='5'){
		    tabTitle = "部门查询";
			tabUrl = param.baseUrl + "/page/user/department.jsp";
		}else if(nodeId=='7'){
		    tabTitle = "字典查询";
			tabUrl = param.baseUrl + "/page/user/dictionary.jsp";
		}else if(nodeId=='setting2'){
			tabTitle = "系统设置";
			tabUrl = param.baseUrl + "/websrc/page/system/setting.jsp";
		}
		// 	打开Tab页
		Anynote.openTab(tabTitle, tabUrl);
	}
	return systemAccordion;
}


/**
 * 将菜单加入到快捷菜单
 * @param baseUrl	baseUrl
 * @param text		菜单名称
 * @param url 		菜单URL
 */
Menu.addFavoriteMenu = function(baseUrl, text, url){
	if(baseUrl=='' || text=='' || url==''){
		Ext.Msg.alert('错误', '参数错误.');
		return;
	}else{
		var params = {};
		params.metaKey = 'favoriteMenu';
		params.metaValue = text+'::'+url;
		// 发送请求
		Anynote.ajaxRequest({
			baseUrl: baseUrl,
			baseParams: params,
			action: '/userMetaAction.do?method=addFavoriteMenu',
			callback: function(jsonResult){
				var homeTree = Ext.getCmp('homeTreePanel');
				Anynote.reloadTreeNode(homeTree, null, function(){
					homeTree.expandAll();
				});
			},
			showWaiting: true,
			failureMsg: '添加失败.'
		});
	}
}


		


